# We need to specify a minimum required version.
# The version of CMake in Ubuntu 12.04 is 2.8.something,
# so we'll use this.
cmake_minimum_required(VERSION 2.8)

# Initialize our project
project(Mindsweeper)

# This finds the SFML package so we can link with it.
# You need to specify the modules in use (in the form of a space-separated
# list at the end of the command).
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
find_package(SFML REQUIRED window system)
include_directories(${SFML_INCLUDE_DIR})

# Generate documentation via Doxygen
# Find the package (for the doxygen command)
find_package(Doxygen)
# Check if we've found it (skip if not)
if (DOXYGEN_FOUND)
	# This converts the template file Doxyfile.in into the final file, Doxyfile
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
	# This adds a target to the make command, so `make doc` will compile the documentation
	# See http://majewsky.wordpress.com/2010/08/14/tip-of-the-day-cmake-and-doxygen/ if you wish to make this
	# run as part of the `all` target (so `make` alone will build the documentation).
	# We'll see how we like it this way first, though.
	add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating Doxygen documentation" VERBATIM)
endif(DOXYGEN_FOUND)

add_executable(mindsweeper src/mindsweeper.cpp)

# Add src to the include directories so modules can include each other.
include_directories(src/)

# Add in the src directory, so CMake will recurse through it
add_subdirectory(src)

# Link in our libraries
target_link_libraries(mindsweeper main)
target_link_libraries(mindsweeper maze)

# And system libraries
target_link_libraries(mindsweeper ${SFML_LIBRARIES})
target_link_libraries(mindsweeper GLU) # For some reason, FindSFML doesn't automatically link this in.)

# Actually install the final executable into our install/bin/ directory
install(TARGETS mindsweeper DESTINATION bin)
